import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * This is a white blood cell. This kind of cell has the job to catch 
 * bacteria and remove them from the blood.
 * 
 * @author Michael Kölling
 * @version 0.1
 */
public class WhiteCell extends Actor
{
    private int count = 0;
    private int time = 1000;
    
    public void act() 
    {
        checkKeyPress();
        time--;
        if(isTouching(Bacteria.class))
        {
            Greenfoot.playSound("slurp.wav");
            removeTouching(Bacteria.class);
            count+=20;
        }
        
        if(isTouching(Virus.class))
        {
            Greenfoot.playSound("slurp.wav");
            removeTouching(Virus.class);
            count-=100;
        }
        
        if(time == 0)
        {
            Greenfoot.playSound("fanfare.wav");
            Greenfoot.stop();
        }
        
        if(count < 0)
        {
            Greenfoot.playSound("game-over.wav");
            Greenfoot.stop();
        }
        Bloodstream w = (Bloodstream)getWorld();
        w.showScore(count,time);
    }
    
    /**
     * Check whether a keyboard key has been pressed and react if it has.
     */
    private void checkKeyPress()
    {
        if (Greenfoot.isKeyDown("up")) 
        {
            setLocation(getX(), getY()-6);
        }
        
        if (Greenfoot.isKeyDown("down")) 
        {
            setLocation(getX(), getY()+6);
        }
        
        if (Greenfoot.isKeyDown("left")) 
        {
            setLocation(getX()-6, getY());
        }
        
        if (Greenfoot.isKeyDown("right")) 
        {
            setLocation(getX()+6, getY());
        }
    }
}
